from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
from selenium import webdriver
from time import sleep
# MyLoginURL = 'https://200.200.156.248/WLAN/index.php'
# MyWeb = webdriver.Chrome()

def VAC_Login(Str, Admin, Password):
    # open the URL
    MyWeb = webdriver.Chrome()
    MyWeb.get('https://%s/WLAN/index.php'%Str)
    sleep(1)

    # Check the web https certificate
    if MyWeb.find_element_by_id("primary-button"):
        MyWeb.find_element_by_xpath("//*[@id='details-button']").click()
        sleep(1)
        MyWeb.find_element_by_xpath("//*[@id='proceed-link']").click()
        sleep(1)

    # input my login info
    MyWeb.find_element_by_xpath("//*[@id='login_user']").send_keys(Admin)
    MyWeb.find_element_by_xpath("//*[@id='login_password']").send_keys(Password)

    # judgment the boxfox
    if MyWeb.find_element_by_name("checkProtocol").is_selected():
        MyWeb.find_element_by_xpath("//*[@id='sub']").click()
    else:
        MyWeb.find_element_by_name("checkProtocol").click()
        MyWeb.find_element_by_xpath("//*[@id='sub']").click()
    sleep(1)
    return MyWeb

def Mycase(Myweb):
    Myweb.find_element_by_xpath("//*[@id='ext-gen34']/div").click()
    sleep(1)
    # 配置AP
    Myweb.find_element_by_xpath("//span[text()='无线接入点']").click()
    sleep(15)
    # 选择AP
    Myweb.find_element_by_xpath("//span[text()='AP5636X1']").click()
    sleep(10)
    # 进入高级参数配置页面
    # 参数配置
    Myweb.find_element_by_xpath('//*[@id="ext-gen265"]').click()
    sleep(5)
    # 
    Myweb.find_element_by_xpath('//span[text()="信道功率"]').click()
    sleep(1)
    # 配置2.4G
    Myweb.find_element_by_xpath('//*[@id="ext-comp-4191"]').click()
    sleep(1)
    Myweb.find_element_by_xpath('//*[@id="ext-gen582"]/div[2]').click()
    sleep(1)
    Myweb.find_element_by_xpath('//*[@id="ext-comp-4192"]').click()
    sleep(1)
    Myweb.find_element_by_xpath('//*[@id="ext-gen615"]/div[5]').click()
    
def Logout_all_User(Myweb):
    sleep(5)
    Myweb.find_element_by_xpath("//span[text()='在线用户']").click()
    sleep(5)
    # 配置AP
    Myweb.find_element_by_class_name(' x-btn-text sf-ico-logout-all-user').click()
    sleep(1)
    Myweb.find_element_by_xpath('//*[@id="ext-gen4023"]').click()
    sleep(15)

